<?php	include_once('config/db.php');
		include_once('functions/loginLib.php');
if(!isset($_SESSION['logged_in'])) {
header('location:login.php');}
if(isset($_REQUEST['update'])){
	if($_REQUEST['contact']=='' && $_REQUEST['email']==''){
		$error=TRUE;
}
elseif(!is_numeric($_REQUEST['contact'])){
	$err_contact=TRUE;
}
elseif(!preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])){
	$err_email=TRUE;
}
else{
	$query=edit_info($_SESSION['contact'], $_SESSION['email']);
	$nice=TRUE;
}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css"/>
<title>Untitled Document</title>
</head>

<body>
<div id="header">
<div id="logo">
  <p>&nbsp;</p>
  <div id="apDiv1"><img src="image/logo.png" alt="" width="500" height="100" /></div>
  <p>&nbsp;</p>
</div>
</div>
<div id="con-body">
  <h4>Welcome: <a href="index.php"><?php echo $_SESSION['name'];?></a> | <a href="change.php">Change Password</a> | <a href="edit.php">Edit Profile</a> | <a href="logout.php">Logout</a></h4>
<?php include('extension/left_bar.php');?>

  <div id="right_container">
<?php if(isset($error)):?>
<div id="error">Empty field</div>
<?php elseif(isset($err_contact)):?>
<div id="error">Invalid Contact number.</div>
<?php elseif(isset($err_email)):?>
<div id="error">Invalid email.</div>
<?php elseif(isset($nice)):?>
<div id="success">Success update</div>
<p><?php endif;?></p>
<h3>Edit Profile</h3>
          <?php
if(isset($_POST['update'])){
	$uploaddir="user_photo";
	$uploadfile =basename($_FILES['nimage1']['name']);
	$filename = basename($_FILES['nimage1']['name']);
	$user =$_SESSION['user'];
	if (move_uploaded_file($_FILES['nimage1']['tmp_name'], "$uploaddir/$uploadfile")) 
	{
	mysql_query("UPDATE user SET picture= '$uploadfile' WHERE user = '$user'");
	}
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data">
  <p>
    <label for="contact"></label>
  </p>
  <table width="316" border="0">
    <tr>
      <td>Contact:</td>
      <td><input name="contact" type="text" id="contact" value="<?php echo $_SESSION['contact']; ?>" size="30" /></td>
    </tr>
    <tr>
      <td>Email: </td>
      <td><input name="email" type="text" id="email" value="<?php echo $_SESSION['email']; ?>" size="30" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="file" name="nimage1" id="nimage1" class="button black small"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="update" type="submit" class="blue" id="update" value="Update" /></td>
    </tr>
  </table>
</form>

            <p>
              
            </p>
</div>
<div id="clear">
</div>
</div>
</body>
</html>